#include<iostream>
#include<cmath>
#include<string>
using namespace std;
typedef long long LL;
const int N = 1010;
LL f[N];
LL s[N];
int n, x;
LL fun(int num)
{
	LL ans = 1;
	for (int i = 1; i <= num; i++) {
		ans *= i;
	}
	return ans;
}
int main()
{
	cin >> n >> x;
	for (int i = 1; i <= n; i++) {
		int k;
		cin >> k;
		s[i] = s[i - 1] + fun(k);
	}
	LL ans = 0;
	while (x--) {
		int l, r;
		cin >> l >> r;
		ans += s[r] - s[l - 1];
	}
	cout << ans << endl;
	return 0;
}